package com.kolon.framework.util;

import java.util.Iterator;
import java.util.LinkedHashMap;

import org.jdom.CDATA;
import org.jdom.Document;
import org.jdom.Element;


/**
 * XML 유틸 클래스
 * @author stone
 *
 */
public class XmlUtil {
	
	/**
	 * Document RootElement 생성하는 함수
	 */
	public Document make(String rootStr) {
		Element element = new Element(rootStr);
		Document document = new Document(element);
		return document;
	}
	
	/**
	 * Element 추가하는 함수
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Element addElement(Element targetElement, LinkedHashMap<String, Object> data) {
		Iterator<String> it = data.keySet().iterator();
		while(it.hasNext()) {
			String key = it.next();
			Element childElement = new Element(key);
			if(data.get(key) instanceof LinkedHashMap) {
				addElement(childElement, (LinkedHashMap)data.get(key));
			} else {
				childElement.addContent(ComUtil.nullChk(String.valueOf(data.get(key))));
			}
			targetElement.addContent(childElement);
		}
		return targetElement;
	}
	
}
